package com.bj58.wuxian.lucene.utils;

import org.junit.Test;

import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;

public class Pinyin4jUtil {
	
	
	public static String hanziToPinyin(String hanzi) throws BadHanyuPinyinOutputFormatCombination{
		HanyuPinyinOutputFormat outputFormat=new HanyuPinyinOutputFormat();
		outputFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
		outputFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
		outputFormat.setVCharType(HanyuPinyinVCharType.WITH_U_UNICODE);
		return PinyinHelper.toHanYuPinyinString(hanzi, outputFormat, "'", false);
	}
	
	@Test
	public void test(){
		try {
			System.out.println(Pinyin4jUtil.hanziToPinyin("不知道该怎么办"));
		} catch (BadHanyuPinyinOutputFormatCombination e) {
			e.printStackTrace();
		}
	}

}
